The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, the approaches described in this section are not prior art to the claims in this application and are not admitted to be prior art by inclusion in this section.
The physical memory of a computing system is comprised of pages that are allocated as needed among different processes that are running on the system. Some pages are allocated to the kernel, and therefore such pages are referred to as kernel pages, while other pages are allocated to one or more user processes (e.g., applications), and therefore such pages are referred to as user pages.
At the startup of the system, the kernel process is the first to be executed, and pages in the physical memory are allocated to the kernel (e.g., kernel pages). When one or more applications are started, additional pages within the physical memory are allocated to those applications (e.g., user pages). Since pages are typically allocated one after another according to the ordering of the pages in the physical memory, at the end of starting up the system, the kernel pages are generally grouped together within the physical memory while the user pages are grouped together by application.
Over time, some processes will end, freeing up the associated pages in the physical memory, while existing processes may require additional pages in the physical memory or new processes will start that require some of the pages in the physical memory. In some systems, the kernel pages and user pages within the physical memory can be intermixed. As a result of different processes starting and ending and processes needing less or more memory, the kernel pages tend to no longer be grouped together within the physical memory and are instead intermixed among user pages for the applications. Similarly, the pages for different applications can become intermixed among each other and among the kernel pages.
The intermixing of kernel pages and user pages is referred to as fragmentation because the kernel pages and the user pages are no longer grouped together within the physical memory. For example, FIG. 1B illustrates a physical memory 150 comprised of a number of kernel pages and user pages for three different applications denoted as A, B, and C. Because the kernel pages and user pages are intermixed, physical memory 150 can be characterized as being fragmented.
Fragmentation can be a problem in systems that support one or more large pages that are each comprised of two or more pages of a minimum size for the system. As an example, a database application such as that produced by Oracle Corporation often prefers to use larger pages for improved performance, such as 4 MB pages that are comprised of contiguous sets of 512 8K pages in a system with a minimum page size of 8K. As a simplified example, in FIG. 1B, assume that each page 152 is 8K in size and that the system supports a large page size of 32K, which is made up of four contiguous 8K pages. If user application C needs a 32K page, the system can coalesce a 32K large page, such as large page 154a, based on the small 8K pages 152a, 152b, 152c, and 152d. However, if any of the 8K pages are currently being used by another process, the contents of the 8K pages need to be moved to free up the smaller pages.
Moving a user page is typically not difficult or resource intensive because a user page can be flushed to disk. However, moving a kernel is typically difficult, or perhaps not even possible. For example, in some memory systems, kernel pages cannot be moved at all, and therefore if only one page within a large page is allocated to the kernel, the large page cannot be coalesced because the kernel page cannot be moved. As another example, in other memory systems the kernel pages can be moved, or relocated, and therefore such kernel pages can be characterized as being relocatable kernel pages. However, even if relocating kernel pages is possible, kernel page relocation is generally more difficult than relocating user pages. Therefore, kernel page relocation is generally a more resource intensive operation and can significantly impede the performance of the system.
One approach for de-fragmenting a physical memory is to reboot the system. Because pages are typically allocated first to the kernel and therefore are grouped together within the physical memory, with user pages being allocated later as each application is started, the result of rebooting the system is that the physical memory has little, if any, fragmentation among the kernel pages and the user pages.
However, a significant drawback of rebooting the system to de-fragment the physical memory is the time required for rebooting the system, which can be significant. Furthermore, restarting some applications, such as an Oracle database, can also require a significant amount of time. As a result, restarting the system can take a half hour or more, and then restarting each large application can take a half hour or more. For a system that requires high availability for mission critical applications, the time to reboot the system and then restart the large application can result in users being unable to use the application for an unacceptably long period of time. Thus, the users of the system is faced with choosing between making the system unavailable by rebooting to increase performance of the application, or maintaining the required availability by forgoing rebooting the system but having to accept the degraded performance of the application due to the inability of the application to use a sufficient number of large pages.